module page {

    export class HonorPage extends egret.DisplayObjectContainer {

        public static readonly Honor_Page_Close: string = "Honor_Page_Close";

        private bg: egret.Bitmap;

        private tableUI: ui.TableUI;

        private closeBtn: ui.PushButton;

        public constructor() {
            super();
            this.bg = manager.ResManager.getBitmap("gdbref_png");
            this.addChild(this.bg);
            this.tableUI = new ui.TableUI(2, 140, 50);
            this.addChild(this.tableUI);

            this.init();
            this.tableUI.y = 200;
            this.tableUI.x = this.bg.width - this.tableUI.width >> 1;

            this.closeBtn = new ui.PushButton(manager.ResManager.getBitmap("gngmt_png"));
            this.closeBtn.x = this.bg.width - this.closeBtn.width >> 1;
            this.closeBtn.y = this.bg.height - this.closeBtn.height / 2;
            this.addChild(this.closeBtn);
            this.closeBtn.addEventListener(ui.PushButton.CLICK, this.onClose, this);
            egret.log("显示荣誉榜");
        }

        private onClose(): void {
            this.dispatchEvent(new egret.Event(HonorPage.Honor_Page_Close));
        }

        private init(): void {
            let usetSetting: user.UserSetting = manager.GameManager.getInstance().getUserSetting();
            for (let i: number = 1; i <= 5; i++) {
                let score: number = i * 100;
                let item: HonorPageItem;
                console.log('usetSetting.maxScore' + usetSetting.maxScore)
                if (usetSetting.maxScore >= score) {
                    console.log('HonorPageItem.ACTIVED')
                    item = new HonorPageItem(HonorPageItem.ACTIVED, i);
                } else {
                    console.log('HonorPageItem.NOT_ACTIVED')                    
                    item = new HonorPageItem(HonorPageItem.NOT_ACTIVED, i);
                }

                this.tableUI.add(item);
            }
            this.tableUI.relayout();
        }

    }


    export class HonorPageItem extends egret.DisplayObjectContainer {

        public static readonly NOT_ACTIVED: number = 1;

        public static readonly ACTIVED: number = 2;

        private indexTxt: egret.TextField;

        private statusImg: egret.Bitmap;

        private medalImg: egret.Bitmap;

        private static readonly nbLabels: Array<number> = [0, 100, 200, 300, 400, 500, 600];

        public constructor(status: number, idx: number) {
            super();

            this.addChild(this.medalImg);

            this.indexTxt = new egret.TextField();
            this.indexTxt.text = "得分>" + HonorPageItem.nbLabels[idx] + "获得";
            this.indexTxt.textColor = 0x0;
            this.indexTxt.size = 20;
            this.indexTxt.bold = true;
            this.addChild(this.indexTxt);

            this.indexTxt.x = this.medalImg.width - this.indexTxt.width >> 1;
            this.indexTxt.y = this.medalImg.height + 10;

            this.statusImg.x = this.medalImg.width - this.statusImg.width >> 1;
            this.statusImg.y = this.indexTxt.y + this.indexTxt.height + 10;
            this.addChild(this.statusImg);
        }

    }

}